<template>
  <el-container>
    <el-header class="header">
      <el-row class="row" align="middle" justify="space-between">
        <el-col :span="21">
          <el-space :size="30">
            <router-link to="/" class="title">
              <div>在线简历</div>
            </router-link>
            <el-menu class="menu" mode="horizontal" router>
              <el-menu-item index="/square">热门模板</el-menu-item>
              <el-menu-item index="/mine">我的简历</el-menu-item>
            </el-menu>
          </el-space>
        </el-col>
        <el-col :span="3" style="text-align: right">
          <span class="login" @click="login">登陆</span>
        </el-col>
      </el-row>
    </el-header>
    <el-main class="main">
      <div class="template-detail-container">
        <div class="template-left">
          <img :src="templateData?.cover" />
        </div>
        <div class="template-right">
          <h1 class="h1">{{ templateData?.name }}</h1>
          <el-space class="template-tags">
            <el-tag class="tag">在校/应届 </el-tag>
            <el-tag class="tag">互联网通用</el-tag>
            <el-tag class="tag">极简</el-tag>
            <el-tag class="tag">简单</el-tag>
          </el-space>
          <div class="template-info">
            <el-row class="template-info-item" justify="space-between">
              <span>主题</span>
              <span>{{ templateData?.theme_style }}</span>
            </el-row>
            <el-row class="template-info-item" justify="space-between">
              <span>主题色</span>
              <span>
                <el-tag class="tag" :style="{ background: '#000000' }">
                  #000000
                </el-tag>
              </span>
            </el-row>
          </div>

          <router-link
            :to="{ path: '/editor', query: { templateId: templateData?.id } }"
            class="button"
          >
            <el-button type="primary" size="large" style="width: 100%">
              使用此模板
            </el-button>
          </router-link>
        </div>
      </div>
    </el-main>
  </el-container>
</template>

<script setup lang="ts">
import { Template } from '@/types'
import { onMounted, ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { getTemplate } from './template.request'

const router = useRouter()
const route = useRoute()

const templateData = ref<Template>()

const login = () => {
  router.push('/login')
}

onMounted(async () => {
  const { data } = await getTemplate(route.query.id as string)
  templateData.value = data
})
</script>

<style scoped lang="less">
.header {
  position: relative;
  width: 100%;
  height: 60px;
  z-index: 90;
  padding: 0 10px;
  background-color: #fff;
  box-shadow: 0 0 10px 0 #d0d3db;
  transition: background 0.5s;

  .row {
    margin: 0px 5%;
    height: 100%;

    .title {
      font-size: 24px;
      vertical-align: middle;
      display: inline-block;
      color: #000;
    }

    .menu {
      width: 300px;
      border: none;
    }
    .login {
      cursor: pointer;
    }
  }
}

.main {
  padding: 20px;
  min-height: calc(100vh - 60px);
  background-color: #f0f9ff;

  .template-detail-container {
    margin: 0 auto;
    display: flex;
    width: 1010px;

    .template-left {
      width: 680px;
      height: 959px;
      background-color: #ffffff;

      img {
        width: 100%;
      }
    }

    .template-right {
      margin-left: 30px;
      padding: 20px;
      width: 300px;
      background-color: #fff;

      .h1 {
        font-size: 20px;
        padding: 0px 0px 10px;
        margin: 0;
      }

      .tag {
        color: #fff;
        background-color: rgb(192, 192, 211);
        border: none;
      }

      .template-info {
        margin-top: 20px;
        color: #999;

        .template-info-item {
          padding: 0 10px;
          height: 55px;
          line-height: 55px;
          border-bottom: 1px solid #e9e9e9;
        }
      }

      .button {
        margin: 20px auto 0;
        display: flex;
        justify-content: center;
      }
    }
  }
}
</style>
